Return 404 for invalid session ID in handle_delete#261
Open
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Return 404 for invalid session ID in handle_delete#261koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
handle_delete#261koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
80f8799 to
0a104d4
Compare
## Motivation and Context The MCP specification requires that when a server receives a request containing a session ID that is no longer valid, it MUST respond with HTTP 404 Not Found. `handle_delete` was unconditionally calling `cleanup_session` and returning 200 even for nonexistent session IDs. Ref: https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management > The server MAY terminate the session at any time, after which it MUST respond > to requests containing that session ID with HTTP 404 Not Found. ## How Has This Been Tested? Added tests for DELETE with invalid session ID, and lifecycle tests for delete-then-POST and delete-then-DELETE scenarios. ## Breaking Change DELETE requests with an invalid session ID now return HTTP 404 "Session not found" instead of HTTP 200. However, this change is considered a bug fix because it brings the behavior into compliance with the MCP specification.
0a104d4 to
abc7d6c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
The MCP specification requires that when a server receives a request containing a session ID that is no longer valid, it MUST respond with HTTP 404 Not Found.
handle_deletewas unconditionally callingcleanup_sessionand returning 200 even for nonexistent session IDs.Ref: https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
How Has This Been Tested?
Added tests for DELETE with invalid session ID, and lifecycle tests for delete-then-POST and delete-then-DELETE scenarios.
Breaking Change
DELETE requests with an invalid session ID now return HTTP 404 "Session not found" instead of HTTP 200.
However, this change is considered a bug fix because it brings the behavior into compliance with the MCP specification.
Types of changes
Checklist